// 将对象转换为二维数组
const arr = Object.entries({
  name: "FAEKER",
  name2: "ROOKIE",
});

console.log(arr); // [ [ 'name', 'FAEKER' ], [ 'name2', 'ROOKIE' ] ]

// 将二维数组转换为对象
const ob = Object.fromEntries([
  ["name", "JOKER"],
  ["list", "1,2,3,4"],
]);

console.log(ob); // { name: 'JOKER', list: '1,2,3,4' }

// 将 map 转换为对象
const map = new Map([
  ["name", "zhangsan"],
  ["age", 18],
]);
console.log(Object.fromEntries(map)); // {name: 'zhangsan', age: 18}

/**
 * 案例
 */
const course = {
  math: 80,
  english: 85,
  chinese: 90,
};
const arrEntries = Object.entries(course); // 扁平化二维
const filters = arrEntries.filter(
  (
    [key, val] // 解构
  ) => val > 80
); // 解构筛选
const result = Object.fromEntries(filters); // 转换对象
console.log(result); // { english: 85, chinese: 90 }
